Repository navigation
perf(ios): read keyboard status from one keyboard snapshot - #4642
Conversation
keyboard status read each key's label and frame as its own XCTest element query, about 35 ms per key, which made the runner command take 1.3 s on a 40-key keyboard. One snapshot of the keyboard carries its visibility, frame, and every key's wording and frame, so the read is one round trip (23 ms). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Size Report
Startup median (7 runs, lower is better):
|
|
The PR is ready from this review at d0a94e0, and I found nothing that needs a change before merge. 19 of 20 checks pass and one review check is still queued. There are no conflicts. Not blocking, and you can take or leave these: reuse |
Closes #4641
What
keyboard statuson iOS read each keyboard key'slabelandframeas its own XCTest element query (two resolves per key, about 35 ms each across the keyboard's process boundary). On a 40-key English keyboard that made the runner command take about 1.3 s. The status read now takes onesnapshot()of the keyboard element. That snapshot carries the keyboard's visibility, its frame, and every key's and button's wording and frame, so the whole read is one round trip.The output contract (
visible,returnKey,returnKeyLabel) and the return-key rule inRunnerKeyboardStatusare unchanged. The shared return-key lookup thatkeyboard enterand dismiss use (findKeyboardReturnControl,tapKeyboardDismissControl) is untouched. The diff iskeyboardStatusandobservedKeyboardKeysinRunnerTests+Keyboard.swift, one unit test, and one comment name innavigation/runtime.ts.Where the time went
Before, one
keyboard status --debugon main, from the request ndjson and the runner log:resolve_target_device(explicit--udid,xcrun simctl list)keyboardStatuscommandallElementsBoundByIndex, then about 80 per-elementlabel/frameresolvesFind the KeyboardsnapshotNo
waitForIdle, settle or repeated tree read was involved. The command already ran withwithBoundedInteractionIdleTimeoutIfSupported(.bothSkipped). The cost was only the per-element round trips.Timings
iPhone 17e simulator, iOS 27.0, warm daemon, keyboard up on the Wallet sign-up email field (
explore-example-wallet://auth/sign-up). Wall clock per CLI call including node start, n=8 each, ms. Each run used its own privateAGENT_DEVICE_STATE_DIR.--udid--udidkeyboard statusmediansnapshotmedianRaw samples, main
--udid, status: 1606 1498 1845 1618 1514 2185 1884 1604. Snapshot: 551 378 309 309 304 298 309 530.Branch
--udid, status: 441 580 432 472 624 588 430 480. Snapshot: 302 295 330 310 357 408 376 288.Branch session only, status: 510 233 240 227 228 230 231 242. Snapshot: 271 282 299 333 421 353 286 302.
The remaining gap to
snapshotWith the session alone selecting the device,
keyboard statuscosts about 0.23 s, at or belowsnapshot. With an explicit--udidon every call (as the T3 device wrapper passes), it is about 0.16 s oversnapshot. The cause is outside the status path.resolveCommandDevicetreats an explicit device selector as a fresh selection and re-reads the simulator inventory (resolve_target_device, 256 ms,cacheHit:false).snapshotgoes throughresolveSessionDeviceand skips it. That cost applies to every command that resolves its device throughresolveCommandDevice, so I left it for its own change and kept this PR on the status read path.Output identical before and after
keyboard status --jsonon main and on this branch, for each state:visible: true,returnKey: next,returnKeyLabel: nextvisible: true,returnKey: next,returnKeyLabel: nextvisible: true,returnKey: done,returnKeyLabel: donekeyboard enteron the password field)visible: falseVerification
F25C7515-D67E-4838-BEAC-0AD08DB056EC.1cb2f242ae(before) and this branch with the same runner change at the head before the unit test and formatting pass was added. The runner was rebuilt withpnpm build:xcuitest:ios.testObservedKeyboardKeysReadsKeysThenButtonsFromOneKeyboardSnapshot(iOS only, nightly lane). It checks nested descendants, keys before buttons, the whitespace-only space bar kept, and label-less or non-key elements dropped.pnpm check:xctest-selectionpasses locally. Per the worktree rules, CI validates the rest.🤖 Generated with Claude Code